package com.xkdx.caipiao;

import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.view.View;

import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.presistence.welcome.WelcomeAction;
import com.xkdx.caipiao.presistence.welcome.WelcomePresistence;

public class WelcomeActivity extends ThreadActivity {
	private WelcomeAction action;
	private WelcomePresistence presistence;
	private String devicetype = "2";
	private String platform = "xkdx";
	private String version= "2014.10.20";
	private String devicetoken;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome_caipiao);
		TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(WelcomeActivity.TELEPHONY_SERVICE);
		devicetoken = mTelephonyManager.getDeviceId();

		
	}

	private void LoginMain() {

		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				startThread();
				Intent intent = new Intent(WelcomeActivity.this,
						HomePageActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
			}
		}, 2000);
	}
	@Override
	protected void onPause() {
		super.onPause();
		this.finish();
	}

	@Override
	protected void onStart() {

		super.onStart();
		LoginMain();
	}
	public void startThread() {
//		LoginInfo info = getLoginInfo();
		if (usrSP==null) {
			action = new WelcomeAction(devicetype,platform,version,
					devicetoken,null);
			presistence = new WelcomePresistence(this);
			presistence.setActitons(action);
			presistence.execute();
		}else {
			action = new WelcomeAction(devicetype,platform,version,
					devicetoken,usrSP.getId());
			presistence = new WelcomePresistence(this);
			presistence.setActitons(action);
			presistence.execute();
		}
		


	}

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onBackClick(View view) {
		// TODO Auto-generated method stub
		
	}
}
